<?php

namespace app\logic\model\user;

use app\logic\model\coupon\CouponLogicModel;
use app\logic\model\LogicModel;

class UserCouponLogicModel extends LogicModel
{
    protected $name='user_coupon';
    function coupon(){
        return $this->hasOne(CouponLogicModel::class,'id','coupon_id');
    }
    public function getFindById($id = 0,$user_id = 0){
        if(empty($id) || empty($user_id)){
            return false;
        }
        return self::where('id',$id)
            ->where('user_id',$user_id)
            ->find();
    }
    public static function isHaveByCouponId($coupon_id = 0,$user_id = 0): bool
    {
        if(empty($coupon_id) || empty($user_id)){
            return false;
        }
        return (bool)self::where('coupon_id',$coupon_id)
            ->where('user_id',$user_id)
            ->find();
    }
}